// // ignore_for_file: non_constant_identifier_names, must_be_immutable

// import 'package:flutter/material.dart';

// ///折线图组件
// class LineCharView extends StatefulWidget {
//   EdgeInsets padding = EdgeInsets.zero;
//   double offsetX_label = 5;
//   double offsetY_label = 2;
//   double minX;
//   double maxX;
//   List<double>? data = [];
//   final String? Function(double minY, double maxY, double currentY)? axisX_label;
//   final String? Function(double minX, double maxX, double currentX)? axisY_label;
//   final Color borderColor;
//   final Color axisX_Color;
//   final Color axisY_Color;
//   final Color lineColor;
//   final Color labelColor;
//   final Color backgroudColor;
//   final double borderWidth;
//   final double axisX_Width;
//   final double axisY_Width;
//   final double lineWidth;
//   LineCharView({
//     super.key,
//     required this.padding,
//     required this.minX,
//     required this.maxX,
//     this.borderWidth = 1.0,
//     this.axisX_Width = 1.0,
//     this.axisY_Width = 1.0,
//     this.lineWidth = 1.0,
//     this.borderColor = Colors.black,
//     this.axisX_Color = Colors.black,
//     this.axisY_Color = Colors.black,
//     this.lineColor = Colors.black,
//     this.labelColor = Colors.black,
//     this.backgroudColor = Colors.white,
//     this.data,
//     this.axisX_label,
//     this.axisY_label,
//   });

//   @override
//   State<LineCharView> createState() => _LineCharViewState();
// }

// class _LineCharViewState extends State<LineCharView> {
//   Size _size = Size.zero;
//   @override
//   Widget build(BuildContext context) {
//     return LayoutBuilder(builder: (BuildContext context, BoxConstraints constrains) {
//       _size = Size(constrains.maxWidth, constrains.maxHeight);
//       return Container(
//         padding: widget.padding,
//         color: widget.backgroudColor,
//         width: _size.width,
//         height: _size.height,
//         child: CustomPaint(
//           size: Size(_size.width - widget.padding.left - widget.padding.right,
//               _size.height - widget.padding.top - widget.padding.bottom),
//           painter: LineChartPainter(
//             padding: widget.padding,
//             minX: widget.minX,
//             maxX: widget.maxX,
//             offsetX_label: widget.offsetX_label,
//             offsetY_label: widget.offsetY_label,
//             borderColor: widget.borderColor,
//             axisXColor: widget.axisX_Color,
//             axisYColor: widget.axisY_Color,
//             lineColor: widget.lineColor,
//             labelColor: widget.labelColor,
//             borderWidth: widget.borderWidth,
//             axisX_Width: widget.axisX_Width,
//             axisY_Width: widget.axisY_Width,
//             lineWidth: widget.lineWidth,
//             data: widget.data,
//             axisX_label: widget.axisX_label,
//             axisY_label: widget.axisY_label,
//           ),
//         ),
//       );
//     });
//   }
// }

// ///绘图类
// class LineChartPainter extends CustomPainter {
//   EdgeInsets padding = EdgeInsets.zero;
//   double offsetX_label;
//   double offsetY_label;
//   double minX;
//   double maxX;
//   List<double>? data = [];
//   final Color borderColor;
//   final Color axisXColor;
//   final Color axisYColor;
//   final Color lineColor;
//   final Color labelColor;

//   final double borderWidth;
//   final double axisX_Width;
//   final double axisY_Width;
//   final double lineWidth;
//   final String? Function(double, double, double)? axisX_label;
//   final String? Function(double, double, double)? axisY_label;

//   LineChartPainter({
//     required this.padding,
//     required this.minX,
//     required this.maxX,
//     required this.offsetX_label,
//     required this.offsetY_label,
//     required this.borderColor,
//     required this.axisXColor,
//     required this.axisYColor,
//     required this.lineColor,
//     required this.labelColor,
//     required this.borderWidth,
//     required this.axisX_Width,
//     required this.axisY_Width,
//     required this.lineWidth,
//     required this.data,
//     required this.axisX_label,
//     required this.axisY_label,
//   });

//   @override
//   void paint(Canvas canvas, Size size) {
//     double h = size.height.roundToDouble();
//     double w = size.width.roundToDouble();
//     // 1,绘制边框
//     _drawBorder(canvas, Size(w, h));

//     // 2,绘制 X 和 Y 轴
//     //X轴
//     _drawX_aXis(canvas, Size(w, h));

//     //Y轴
//     _drawY_aXis(canvas, Size(w, h));

//     /// 3,绘制线条
//     _drawLine(canvas, Size(w, h));
//   }

//   ///绘制边框
//   void _drawBorder(Canvas canvas, Size size) {
//     final borderPaint = Paint()
//       ..color = borderColor
//       ..strokeWidth = borderWidth
//       ..style = PaintingStyle.stroke;

//     canvas.drawRect(
//       Rect.fromLTWH(0, 0, size.width, size.height),
//       borderPaint,
//     );
//   }

//   ///绘制X轴
//   void _drawX_aXis(Canvas canvas, Size size) {
//     for (double i = 0; i <= size.height; i++) {
//       if (axisX_label != null && axisX_label!(0, size.height, i) != null) {
//         ///绘制X轴 的标签
//         final text = axisX_label!(0, size.height, i);
//         _drawText(canvas, text as String, Offset(-padding.left, i), true);

//         final xPaint = Paint()
//           ..color = axisXColor
//           ..strokeWidth = axisX_Width
//           ..style = PaintingStyle.stroke;

//         final xpath = Path();
//         xpath.moveTo(0, i);
//         xpath.lineTo(size.width, i);
//         canvas.drawPath(xpath, xPaint);
//       }
//     }
//   }

//   ///绘制Y轴
//   void _drawY_aXis(Canvas canvas, Size size) {
//     for (double i = 0; i <= size.width; i++) {
//       if (axisY_label != null && axisY_label!(0, size.width, i) != null) {
//         ///绘制Y轴 的标签
//         final text = axisY_label!(0, size.width, i);
//         _drawText(canvas, text as String, Offset(i, size.height + offsetY_label), false);

//         final yPaint = Paint()
//           ..color = axisYColor
//           ..strokeWidth = axisY_Width
//           ..style = PaintingStyle.stroke;

//         final ypath = Path();
//         ypath.moveTo(i, 0);
//         ypath.lineTo(i, size.height);
//         canvas.drawPath(ypath, yPaint);
//       }
//     }
//   }

//   /// 绘制文字
//   void _drawText(Canvas canvas, String text, Offset position, bool isAxisX) {
//     var textStyle = TextStyle(
//       color: labelColor,
//       fontSize: isAxisX ? 10 : 8,
//     );

//     final textSpan = TextSpan(
//       text: text,
//       style: textStyle,
//     );

//     final textPainter = TextPainter(text: textSpan, textDirection: TextDirection.ltr, textAlign: TextAlign.start);
//     textPainter.layout();

//     Offset offsetsss = isAxisX
//         ? Offset(-textPainter.width - offsetX_label, position.dy - 6)
//         : Offset(position.dx - textPainter.width / 2, position.dy);
//     textPainter.paint(canvas, offsetsss);
//   }

//   ///绘制线条
//   void _drawLine(Canvas canvas, Size size) {
//     if (data != null) {
//       final paint = Paint()
//         ..color = lineColor
//         ..strokeWidth = lineWidth
//         ..style = PaintingStyle.stroke;

//       ///计算真实高度
//       double scale = size.height / (maxX - minX);
//       bool is_start = false;
//       final path = Path();
//       for (var i = 0; i < data!.length; i++) {
//         double y = (maxX - data![i]) * scale - lineWidth / 2.0;

//         ///第一次添加
//         if (is_start == false && y < size.height) {
//           path.moveTo(i.toDouble() + 1, y);
//           is_start = true;
//         } else {
//           ///限制线条，不能绘制到外面
//           if (y <= size.height) {
//             path.lineTo(i.toDouble(), y);
//           }
//         }
//       }
//       canvas.drawPath(path, paint);
//     }
//   }

//   @override
//   bool shouldRepaint(covariant CustomPainter oldDelegate) {
//     return false;
//   }
// }
